package com.qf.controller;

import com.qf.pojo.DtsCoupon;
import com.qf.pojo.DtsCouponUser;
import com.qf.service.DtsCouponService;
import com.qf.service.DtsCouponUserService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/coupon")
public class DtsAdminCouponController {
    @Autowired
    DtsCouponService couponService;
    @Autowired
    DtsCouponUserService couponUserService;

    @PostMapping("/delete")
    public Object delete(@RequestBody DtsCoupon coupon){
        couponService.delete(coupon);
        return ResponseUtil.ok();
    }

    @PostMapping("/update")
    public Object update(@RequestBody DtsCoupon coupon){
        DtsCoupon coupons = couponService.update(coupon);
        return ResponseUtil.ok(coupons);
    }

    @GetMapping("/read")
    public Object read(Integer id) {
        DtsCoupon DtsCouponUser = couponService.findById(id);
        return ResponseUtil.ok(DtsCouponUser);
    }

    @GetMapping("/listuser")
    public Object listuser(
            @RequestParam(value = "page",required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit",required = false, defaultValue = "20")Integer limit,
            Integer couponId,Integer userId,Integer status,String sort,String order
    ){
        Map<String, Object> data = couponUserService.queryPage(page,limit,couponId,userId,status,sort,order);
        return ResponseUtil.ok(data);
    }

    @PostMapping("/create")
    public Object create(@RequestBody DtsCoupon coupon){
        DtsCoupon coupons = couponService.create(coupon);
        return ResponseUtil.ok(coupons);
    }

    @GetMapping("/list")
    public Object list(
            @RequestParam(value = "page",required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit",required = false, defaultValue = "20")Integer limit,
            String name,Integer type,Integer status,String sort,String order
    ){
        Map<String, Object> data = couponService.queryPage(page,limit,name,type,status,sort,order);
        return ResponseUtil.ok(data);
    }
}